package com.zdsoft.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.zdsoft.entity.Article;
import com.zdsoft.vo.ArticleUpdateVO;
import com.zdsoft.vo.ArticleVO;

public interface IArticleMapper {
	@Insert("INSERT INTO article (title,info_id) VALUES (#{title},#{infoId})")
	int addArticle(Article a);
	@Delete("DELETE FROM article WHERE id=#{id}")
	int del(Long id);
	@Select("SELECT a.id, a.title ,a.info_id,ai.content from article a INNER JOIN article_info ai ON a.info_id =ai.id WHERE a.id=#{id} ")
	 ArticleUpdateVO	findVOById(Long id);
	
	@Update("UPDATE article SET title=#{title} WHERE id=#{id} ")
	int update(ArticleUpdateVO av);
	@Select("<script>"
			+ "SELECT count(*) FROM article"
			+ "<where>"
			+ "<if test=' title!=null and title!=\"\"'> "
			+ " and title LIKE concat(concat('%',#{title}),'%')"
			+ "</if> "
			+ "</where>"
			+ "</script>")
	Long getTotal(Map<String,Object> map);
	
	@Select("<script>"
			+ "SELECT a.title,ai.content FROM article a INNER JOIN article_info ai on a.info_id=ai.id   "+
			"<where>"
			+ "<if test='title!=null and title!=\"\"'>"
			+ " and (a.title LIKE concat(concat('%',#{title}),'%') "
			+ " or  ai.content LIKE  concat(concat('%',#{title}),'%'))"
			+ "</if> "
			+"</where>"
			
			+ " limit #{page},#{size}"
			
			
				
			
			+ "</script>")
	
	List<ArticleVO> getArticleList(Map<String ,Object> map);

}
